package com.example.mymvvmdemo.models.main.fragment.mine.adapter;

import android.content.Context;

import com.example.mymvvmdemo.R;
import com.example.mymvvmdemo.base.BaseVBAdapter;
import com.example.mymvvmdemo.databinding.ItemMineBinding;
import com.example.mymvvmdemo.entity.CommonEntity;
import com.example.mymvvmdemo.utils.StrUtils;

import java.util.ArrayList;

public class MineAdapter extends BaseVBAdapter<CommonEntity, ItemMineBinding> {

    public MineListener listener;

    public void setListener(MineListener listener) {
        this.listener = listener;
    }

    /**
     * @param context
     */
    public MineAdapter(Context context, ArrayList<CommonEntity> list) {
        super(context);
        setDataList(list);
    }

    @Override
    protected void updateData(ItemMineBinding bind, CommonEntity item, int position) {

        if (position == 0) {
            bind.clAll.setBackgroundResource(R.drawable.bg_white_top_10_round);
        } else if (position == getDataListSize() - 1) {
            bind.clAll.setBackgroundResource(R.drawable.bg_white_bottom_10_round);
        }

        String title = item.getTitle();
        if (!StrUtils.isEmpty(title)) {
            bind.tvUser.setText(title);
        }

        int resId = item.getResId();
        bind.ivUser.setImageResource(resId);

        bind.clAll.setOnClickListener(view -> {
            if (listener != null) {
                listener.onMineClick(position);
            }
        });

    }

    public interface MineListener {
        void onMineClick(int position);
    }

}
